﻿using System.Collections.Generic;
using System.Linq;

namespace Game.Plugin.Parse
{
    public static class Parsers
    {
        static readonly List<IParser> _List;

        static Parsers()
        {
            _List = new List<IParser>
            {
                new PlusParser(), 
                new MinusParser(),
                new NumberParser(),
                new VariableParser()
            };
        }

        public static void Add(IParser expression)
        {
            _List.Add(expression);
        }

        public static IParser Find(string token)
        {
            var p = _List.FirstOrDefault(e => e.CanParse(token));
            if (p != null)
            {
                return p;
            }

            return PluginManager.Instance.RootPlugin.Find(token);
        }
    }
}
